package com.taoxi.shops.controller;

import com.taoxi.common.annotation.Anonymous;
import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.shops.domain.Store;
import com.taoxi.shops.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实体店列表Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@Api(tags = "实体店列表Controller")
@RestController
@RequestMapping("/shops/store")
public class StoreController extends BaseController {
    @Autowired
    private IStoreService storeService;

    /**
     * 查询实体店列表列表
     */
    @ApiOperation("查询实体店列表列表")
    @PreAuthorize("@ss.hasPermi('shops:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(Store store) {
        startPage();
        List<Store> list = storeService.selectStoreList(store);
        return getDataTable(list);
    }

    /**
     * 导出实体店列表列表
     */
    @ApiOperation("导出实体店列表列表")
    @PreAuthorize("@ss.hasPermi('shops:store:export')")
    @Log(title = "实体店列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Store store) {
        List<Store> list = storeService.selectStoreList(store);
        ExcelUtil<Store> util = new ExcelUtil<Store>(Store.class);
        util.exportExcel(response, list, "实体店列表数据");
    }

    /**
     * 获取实体店列表详细信息
     */
    @ApiOperation("获取实体店列表详细信息")
    @PreAuthorize("@ss.hasPermi('shops:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(storeService.selectStoreById(id));
    }

    /**
     * 新增实体店列表
     */
    @ApiOperation("新增实体店列表")
    @PreAuthorize("@ss.hasPermi('shops:store:add')")
    @Log(title = "实体店列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Store store) {
        return toAjax(storeService.insertStore(store));
    }

    /**
     * 修改实体店列表
     */
    @ApiOperation("修改实体店列表")
    @PreAuthorize("@ss.hasPermi('shops:store:edit')")
    @Log(title = "实体店列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Store store) {
        return toAjax(storeService.updateStore(store));
    }

    /**
     * 删除实体店列表
     */
    @ApiOperation("删除实体店列表")
    @PreAuthorize("@ss.hasPermi('shops:store:remove')")
    @Log(title = "实体店列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(storeService.deleteStoreByIds(ids));
    }

    /**
     * 查询实体店销量排序
     */
    @Anonymous
    @ApiOperation("实体店销量排序")
    @GetMapping("/getSalesSort")
    public TableDataInfo getSalesSort(Store store) {
        startPage();
        List<Store> list = storeService.getSalesSort(store);
        return getDataTable(list);
    }

}
